<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<script type="text/javascript" src="${basePath}/js/jquery-1.7.2.js"></script>
<%-- <script type="text/javascript" src="${basePath}/js/jquery-1.7.2.min.js"></script> --%>
<script type="text/javascript" src="${basePath}/bootstrap/js/bootstrap.js"></script>
<!--[if lte IE 6]>
  <script type="text/javascript" src="${basePath}/js/bootstrap-ie.js"></script>
<![endif]-->
<script type="text/javascript" src="${basePath}/layer/layer.js"></script>



<script>
	//解决 IE8、IE9 不支持 console 问题
	window.console = window.console || (function () {
	  var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
	  = c.clear = c.exception = c.trace = c.assert = function () { };
	  return c;
	})();
	
	// 解决IE8不支持Array.isArray
	if (!Array.isArray) {
	  Array.isArray = function(arg) {
	    return Object.prototype.toString.call(arg) === '[object Array]';
	  };
	}
	
	// form表单序列化成json对象
	$.fn.serializeObject = function()
	{
	    var o = {};
	    var a = this.serializeArray();
	    $.each(a, function() {
	        if (o[this.name] !== undefined) {
	            if (!o[this.name].push) {
	                o[this.name] = [o[this.name]];
	            }
	            o[this.name].push(this.value || '');
	        } else {
	            o[this.name] = this.value || '';
	        }
	    });
	    return o;
	};

	
	var checkFuntion = {
		"check-required" : function(element,msg,errorMsgElement){
			var $e = $(element);
			var $eme = $(errorMsgElement);
			var defaultErrorMsg = "请输入{0}，{0}不能为空";
			
			if(trim($e.val()).length == 0 && $e.is(':visible')){
				if(!$e.hasClass("check-error")){
					$e.addClass("check-error");
					$eme.html(defaultErrorMsg.replace(/\{0\}/g,msg));
					$eme.show();
				}
			}
			else{
				if($e.hasClass("check-error")){
					$e.removeClass("check-error");
				}
				$eme.hide();
			}
		},
		"check-number" : function(element,msg,errorMsgElement){
			var defaultErrorMsg = "{0}只能由数字组成";
			
			checkFuntion["check-custom"](element,msg,errorMsgElement,/^\d*$/,defaultErrorMsg);
			
		},
		"check-float" : function(element,msg,errorMsgElement){
			var defaultErrorMsg = "{0}只能为数字或者整数";
			
			checkFuntion["check-custom"](element,msg,errorMsgElement,/^\d*(\.\d*)?$/,defaultErrorMsg);
			
		},
		"check-character" : function(element,msg,errorMsgElement){
			var defaultErrorMsg = "{0}只能由字母组成";
			
			checkFuntion["check-custom"](element,msg,errorMsgElement,/^[a-zA-Z]+$/,defaultErrorMsg);
			
		},
		"check-nc" : function(element,msg,errorMsgElement){
			var defaultErrorMsg = "{0}只能由数字和字母组成";
			
			checkFuntion["check-custom"](element,msg,errorMsgElement,/^[a-zA-Z0-9]+$/,defaultErrorMsg);
			
		},
		"check-custom" : function(element,msg,errorMsgElement,reg,msgTemple){
			var $e = $(element);
			var $eme = $(errorMsgElement);
			if(reg.test($e.val()) || $e.is(':hidden')){
				if($e.hasClass("check-error")){
					$e.removeClass("check-error");
				}
				$eme.hide();
			}
			else{
				if(!$e.hasClass("check-error")){
					$e.addClass("check-error");
					$eme.html(msgTemple.replace(/\{0\}/g,msg));
					$eme.show();
				}
			}
		}
	};

	var basePath = "${basePath}";
	var defaultPageSize = 7;
	var bindEvent = ["change","blur"];
	
	function getLayerDiv(id){
		return document.getElementById("layui-layer" + id);
	}
	
	function trim(str){
		return str.replace(/^(\s*)|(\s*$)/g,'');
	}

	function showPage(current,pageSize,size){
		if(!size){
			size = defaultPageSize;
		}
		pageSize = pageSize <= 0 ? 1 : pageSize;
		current = current < 1 ? 1 : (current > pageSize ? pageSize : current);
		
		var str = '<div class="pagination pagination-centered">';
		
		str += '<ul style="float: right;box-shadow: none;">';
		str += '<li class="disabled" style="border: none;">';
		str += '<a href="javascript:void(0);" style="border: none;">共'+pageSize+'页 '+total+'条记录 当前'+current+'页 跳转至</a>';
		str += '</li>';
		str += '<li class="disabled">';
		str += '<input id="jumpPageInput" type="text" value="' + current + '" style="margin: 0;width: 40px;float: left;" />';
		str += '</li>';
		str += '<li>';
		str += '<a href="javascript:jumpPage(' + pageSize + ');">GO</a>';
		str += '</li>';
		str += '</ul>';
		
		str += '<ul style="float: left;">';
		
		if(current <= 1){
			str += '<li class="disabled" title="第一页"><a href="javascript:void(0);">«</a></li>';
			str += '<li class="disabled" title="上一页"><a href="javascript:void(0);">‹</a></li>';
		}
		else{
			str += '<li title="第一页"><a href="javascript:list('+1+');">«</a></li>';
			str += '<li title="上一页"><a href="javascript:list('+(current - 1)+');">‹</a></li>';
		}
		
		var half = Math.floor(size / 2);
		var startIndex = 0;
		if(current <= half){
			startIndex = 0;
		}
		else if(current >= (pageSize - half)){
			startIndex = pageSize - size;
		}
		else{
			startIndex = current - half;
			if(size % 2 != 0){
				startIndex--;
			}
		}
		startIndex = startIndex < 0 ? 0 : startIndex;
		for(var i = startIndex;i < startIndex + (size < pageSize ? size : pageSize);i++){
			str += i + 1 == current ? '<li class="disabled"><a href="javascript:void(0);">' + (i + 1) + '</a></li>' : '<li><a href="javascript:list('+(i + 1)+');">' + ( i + 1 ) + '</a></li>';
		}
		
		if(current >= pageSize){
			str += '<li class="disabled" title="下一页"><a href="javascript:void(0);">›</a></li>';
			str += '<li class="disabled" title="最后一页"><a href="javascript:void(0);">»</a></li>';
		}
		else{
			str += '<li title="下一页"><a href="javascript:list('+(current + 1)+');">›</a></li>';
			str += '<li title="最后一页"><a href="javascript:list('+pageSize+');">»</a></li>';
		}
		
		str += '</ul><div class="clearfix"></div></div>';
		$("#pagination").html(str);
	}
	
	function jumpPage(pageSize){
		var page = $("#jumpPageInput").val();
		
		try{
			page = parseInt(page);
		} catch(e){
			console.error(e);
			page = 1;
		}
		
		if(!page){
			page = 1;
		}
		
		page = page < 1 ? 1 : (page > pageSize ? pageSize : page);
		
		$("#jumpPageInput").val(page);
		
		list(page);
	}
	
	function createMovePage(current,pageSize,size){
		if(!size){
			size = defaultPageSize;
		}
		pageSize = pageSize <= 0 ? 1 : pageSize;
		current = current < 1 ? 1 : (current > pageSize ? pageSize : current);
		
		var str = '<div class="pagination pagination-centered">';
		
		str += '<ul>';
		
		if(current <= 1){
			str += '<li class="disabled" title="第一页"><a href="javascript:void(0);">«</a></li>';
			str += '<li class="disabled" title="上一页"><a href="javascript:void(0);">‹</a></li>';
		}
		else{
			str += '<li title="第一页"><a href="javascript:moveList('+1+',oldSeqId);">«</a></li>';
			str += '<li title="上一页"><a href="javascript:moveList('+(current - 1)+',oldSeqId);">‹</a></li>';
		}
		
		var half = Math.floor(size / 2);
		var startIndex = 0;
		if(current <= half){
			startIndex = 0;
		}
		else if(current >= (pageSize - half)){
			startIndex = pageSize - size;
		}
		else{
			startIndex = current - half;
			if(size % 2 != 0){
				startIndex--;
			}
		}
		startIndex = startIndex < 0 ? 0 : startIndex;
		for(var i = startIndex;i < startIndex + (size < pageSize ? size : pageSize);i++){
			str += i + 1 == current ? '<li class="disabled"><a href="javascript:void(0);">' + (i + 1) + '</a></li>' : '<li><a href="javascript:moveList('+(i + 1)+');">' + ( i + 1 ) + '</a></li>';
		}
		
		if(current >= pageSize){
			str += '<li class="disabled" title="下一页"><a href="javascript:void(0);">›</a></li>';
			str += '<li class="disabled" title="最后一页"><a href="javascript:void(0);">»</a></li>';
		}
		else{
			str += '<li title="下一页"><a href="javascript:moveList('+(current + 1)+',oldSeqId);">›</a></li>';
			str += '<li title="最后一页"><a href="javascript:moveList('+pageSize+',oldSeqId);">»</a></li>';
		}
		
		str += '</ul><div class="clearfix"></div></div>';
		
		$("#moveTable").after(str);
	}
	
	
	
	var toDate = function(str){
		var str = str.replace(/[\\\/]/g,'-');
		var array = str.split("-");
		if(array.length > 0 && array.length <= 6){
			switch(array.length){
			case 1: return new Date(array[0],"0","1");break;
			case 2: return new Date(array[0],parseInt(array[1].replace(/^[0]+/,"")) - 1,"1");break;
			case 3: return new Date(array[0],parseInt(array[1].replace(/^[0]+/,"")) - 1,array[2]);break;
			case 4: return new Date(array[0],parseInt(array[1].replace(/^[0]+/,"")) - 1,array[2],array[3]);break;
			case 5: return new Date(array[0],parseInt(array[1].replace(/^[0]+/,"")) - 1,array[2],array[3],array[4]);break;
			case 6: return new Date(array[0],parseInt(array[1].replace(/^[0]+/,"")) - 1,array[2],array[3],array[4],array[5]);break;
			default: return new Date();
			}
		}
		return new Date();
	};
</script>